package test;

import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FileAndDirCreate {
	public static boolean createFile(String path) {
		File file = new File(path);
		if (!path.endsWith(File.separator)) {
			if (file.exists()) {
				System.out.println("file exists, create failed");
				return false;
			} else {
				try {
					file.createNewFile();
//                    System.out.println(" create success");
					return true;
				} catch (IOException e) {
					e.printStackTrace();
					System.out.println("create failed");
				}
			}
		} else {
			if (file.exists()) {
				System.out.println("file exists, create failed");
				return false;
			} else {
				try {
					file.mkdirs();
					return true;
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		return false;
	}

	@Test
	public void test() {
		String str = "(((not null )?(primary key )?)|((primary key )?(not null )?))";

//        String str = "(primary key )?|(not null)?";
//        String str = "(primary key not null)|(not null primary key)";
		Pattern pattern = Pattern.compile(str, Pattern.CASE_INSENSITIVE);
//        String sql = "primary key not null";
		String sql = "not null primary key";
		Matcher matcher = pattern.matcher(sql);

		System.out.println(matcher.matches());
	}
}
